using micromsg;
using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Protocol;
using MicroMsg.Scene;
using MicroMsg.Storage;
using System;
namespace MicroMsg.Plugin.Sns.Scene
{
	public class NetSceneSnsUserPage : NetSceneBaseEx<SnsUserPageRequest, SnsUserPageResponse, SnsUserPageRequest.Builder>
	{
		private const string TAG = "NetSceneSnsUserPage";
		private static NetSceneSnsUserPage _mInstance;
		private SnsUserPageCallBack onPageRsp;
		public static NetSceneSnsUserPage Instance
		{
			get
			{
				if (NetSceneSnsUserPage._mInstance == null)
				{
					NetSceneSnsUserPage._mInstance = new NetSceneSnsUserPage();
				}
				return NetSceneSnsUserPage._mInstance;
			}
		}
		public NetSceneSnsUserPage()
		{
		}
		public NetSceneSnsUserPage(SnsUserPageCallBack snsUserPageCallBack_0)
		{
			this.onPageRsp = snsUserPageCallBack_0;
		}
		public bool getFirstPage(string userName, string strFirstPageMd5 = null)
		{
			base.beginBuilder();
			this.mBuilder.BaseRequest = NetSceneBase.makeBaseRequest(0);
			this.mBuilder.MaxId = 0uL;
			this.mBuilder.FirstPageMd5 = ((strFirstPageMd5 == null) ? "" : strFirstPageMd5);
			this.mBuilder.Username = userName;
			Contact contact = StorageMgr.contact.method_0(userName);
			if (contact != null)
			{
				this.mBuilder.Source = contact.nAddContactScene;
			}
			this.mSessionPack.mCmdID = 99;
			base.endBuilder();
			return true;
		}
		public bool getNextPage(string userName, ulong maxID, ulong minID = 0uL, uint LastRequestTime = 0u)
		{
			base.beginBuilder();
			this.mBuilder.BaseRequest = NetSceneBase.makeBaseRequest(0);
			this.mBuilder.MaxId = maxID;
			this.mBuilder.MinFilterId = minID;
			this.mBuilder.LastRequestTime = LastRequestTime;
			this.mBuilder.FirstPageMd5 = "";
			this.mBuilder.Username = userName;
			Contact contact = StorageMgr.contact.method_0(userName);
			if (contact != null)
			{
				this.mBuilder.Source = contact.nAddContactScene;
			}
			this.mSessionPack.mCmdID = 99;
			base.endBuilder();
			return true;
		}
		public bool doScene(string userName, bool isFirstPage, ulong lastID)
		{
			base.beginBuilder();
			this.mBuilder.BaseRequest = NetSceneBase.makeBaseRequest(0);
			if (isFirstPage)
			{
				if (StorageMgr.snsPage.method_1(userName) == null)
				{
					this.mBuilder.FirstPageMd5 = "";
					this.mBuilder.MaxId = 0uL;
				}
				else
				{
					this.mBuilder.FirstPageMd5 = "";
					this.mBuilder.MaxId = 0uL;
				}
			}
			else
			{
				this.mBuilder.FirstPageMd5 = "";
				this.mBuilder.MaxId = lastID;
			}
			this.mBuilder.Username = userName;
			this.mSessionPack.mCmdID = 99;
			base.endBuilder();
			return true;
		}
		protected override void onFailed(SnsUserPageRequest request, SnsUserPageResponse response)
		{
			Log.smethod_1("NetSceneSnsUserPage", "send request failed");
			EventCenter.postEvent(EventConst.ON_NETSCENE_SNS_USER_PAGE_ERR, RetConst.MM_ERR_CLIENT, null);
			if (this.onPageRsp != null)
			{
				this.onPageRsp(-1, null);
			}
		}
		protected override void onSuccess(SnsUserPageRequest request, SnsUserPageResponse response)
		{
			SnsRetCode ret = (SnsRetCode)response.BaseResponse.Ret;
			if (ret != SnsRetCode.MMSNS_MM_OK && ret != SnsRetCode.MMSNS_RET_ISALL && ret != SnsRetCode.MMSNS_RET_PRIVACY)
			{
				Log.smethod_1("NetSceneSnsUserPage", "send request failed ret =" + ret);
				EventCenter.postEvent(EventConst.ON_NETSCENE_SNS_USER_PAGE_ERR, ret, null);
				if (this.onPageRsp != null)
				{
					this.onPageRsp(-1, null);
				}
				return;
			}
			if (this.onPageRsp != null)
			{
				this.onPageRsp((int)ret, response);
			}
			if (response.ObjectListList.get_Count() == 0)
			{
				return;
			}
			EventCenter.postEvent(EventConst.ON_NETSCENE_SNS_USER_PAGE_SUCCESS, ret, null);
		}
	}
}
